package com.egghiro.framework.j2se.game.core.model.actor;

import java.awt.Point;

public abstract class Layer implements IPoint2D,IPainter{
    private Point ulPosition;// upper-left corner

    private int width;
    private int height;
    
    private boolean isVisible;

    public final boolean isVisible() {
        return isVisible;
    }

    public void setVisible(boolean isVisible) {
        this.isVisible = isVisible;
    }

    public Layer(int width, int height) {
        this.isVisible = true;
        ulPosition = new Point();
        this.width = width;
        this.height = height;
    }

    /**
     * @return 左上角X坐标
     */
    public final int getX() {
        return ulPosition.x;
    }
    
    /**
     * @return 左上角Y坐标
     */
    public final int getY() {
        return ulPosition.y;
    }
    
    public int get2DX() {
        return getX() + getWidth() / 2;
    }

    public int get2DY() {
        return getY() + getHeight() / 2;
    }

    public void setPosition(int x, int y) {
        synchronized (ulPosition) {
            ulPosition.setLocation(x, y);
        }
    }

    public void move(int dx, int dy) {
        synchronized (ulPosition) {
            ulPosition.translate(dx, dy);
        }
    }

    public final int getWidth() {
        return this.width;
    }

    public final int getHeight() {
        return this.height;
    }

    public void setSize(int width, int height) {
        if (width < 1 || height < 1)
            throw new IllegalArgumentException();

        this.width = width;
        this.height = height;
    }
}
